<?php
declare (strict_types = 1);

namespace app\sk\tpl;
use app\core\Res;


class ViewIndex extends Layui
{
    public function setFormInput($p){
        $this->_index['toform'][]=$p;
    }

    public function setJsCols($p){
        $this->_index['cols']=$p;
    }

    public function setMtableUrl($p){
        $this->_index['mtableurl']=$p;
    }

    public function setExportUrl($p){
        $this->_index['ExportUrl']=$p;
    }

    public function setToolbar($p){
        $this->_index['toolbar']=$p;
    }

    public function setTitleEvent($p){
        $this->_index['TitleEvent']=$p;
    }

    public function setTbBar($p){
        $this->_index['TbBar']=$p;
    }

    public function setTbEvent($p){
        $this->_index['TbEvent']=$p;
    }
    

   public function view(){
        echo $this->header();
        $hiddenParams=['relation_id','relation_type'];
        $hiddenInput=$this->hiddenInputList($hiddenParams);
        $inputList='';
        $buttonList='';
        $dateJsList='';
        $showLayerJsList='';

        $cols='';
        $mtableurl='';
        $ExportUrl='';
        $toolbar='';
        $TitleEvent='';

        $TbBar='';
        $TbEvent='';
        foreach($this->_index as $key=>$v){
            if($key=='toform'){
                foreach($v as $toform){
                    $type=Res::kv($toform,'type');
                    if($type=='input'){
                        $inputList .=$this->formInput($toform);
                    }
                }
            }
            if($key=='cols'){
                $cols=$v;
            }
            if($key=='mtableurl'){
                $mtableurl=$v;
            }

            if($key=='toolbar'){
                $toolbar=$v;
            }


            if($key=='TitleEvent'){
                $TitleEvent=$v;
            }

            if($key=='TbBar'){
                $TbBar=$v;
            }

            if($key=='TbEvent'){
                $TbEvent=$v;
            }

            if($key=='ExportUrl'){
                $ExportUrl=$v;
            }
        }
       
        $inputParams=[
            'xinhao'=>'',
            'titleName'=>'关键字',
            'inputType'=>'text',
            'inputName'=>'keywords',
            'verType'=>'',
            'verify'=>'',
            'onkeyup'=>'',
            'disabled'=>'',
        ];
        $inputList .=$this->formInput($inputParams);

        $inputParams=[
            'xinhao'=>'',
            'titleName'=>'创建时间',
            'inputName'=>'createDateSel',
            'verType'=>'',
            'verify'=>'',
            'onkeyup'=>'',
            'disabled'=>'',
        ];
        $inputList .=$this->selectDate1($inputParams);
        $dateJsList.=$this->selectJsDate1($inputParams).PHP_EOL;

        $buttonParams=[
            [
                'titleName'=>'搜索',
                'buttonName'=>'mxTbSearch',
                'buttonIcon'=>'&#xe615;',
            ],
            [
                'titleName'=>'重置',
                'buttonName'=>'mxReset',
                'buttonIcon'=>'&#xe669;',
            ],
        ];
        
        $buttonList .=$this->formSearchButton($buttonParams);
        $searchForm1=[
            'FormId'=>'myForm',
            'hiddenInput'=>$hiddenInput,
            'inputList'=>$inputList,
            'buttonList'=>$buttonList,
        ];
        $formFrame=[
            'FormInfo'=>$this->searchForm1($searchForm1),
            'TableInfo'=>$this->searchTable1(['TableId'=>'myTable']),
        ];
        echo $this->formFrame1($formFrame);

        $FunInfo=
<<<EOF
$("#relation_id").val(selectData.id);
$("#company_name").val(selectData.company_name);
$("#relation_type").val(selectData.relation_type);
$("#customer_name").val('');
EOF;
        $companyFunParams=[
            'FunName'=>'CompanyData',
            'FunInfo'=>$FunInfo
        ];
        $companyFun=$this->acceptFunction1($companyFunParams);

        $FunInfo=
<<<EOF
$("#relation_id").val(selectData.id);
$("#customer_name").val(selectData.customer_name);
$("#relation_type").val(customer_relation_type);
$("#company_name").val('');
EOF;
        $customerFunParams=[
            'FunName'=>'CustomerData',
            'FunInfo'=>$FunInfo
        ];
        $customerFun=$this->acceptFunction1($customerFunParams);

        $jsParams=[
           // 'tableDataArray'=>['tableData','tableData1'],
           // 'acceptFunction'=>[$companyFun,$customerFun],
           // 'dateJs'=>$dateJsList,
           // 'showLayerJs'=>$showLayerJsList,
            'cols'=>$cols,
            'mtableurl'=>$mtableurl,
            'toolbar'=>$toolbar,
            'TitleEvent'=>$TitleEvent,
            'TbBar'=>$TbBar,
            'TbEvent'=>$TbEvent,
            'ExportUrl'=>$ExportUrl
        ];
        echo $this->jsIndex($jsParams);
   }

}